import { createSlice } from '@reduxjs/toolkit'
//获取本地存储信息  
const userSlice = createSlice({
  name: 'user',//名称 任意写 必写属性
  initialState: {//user的函数的初始化state
    username:'默认名称',
    token:'',
    isLogin:false
  },
  reducers: {//操作actions的动作 -- 操作数据initialState
    setUser:(state,actions)=>{
        state = actions.payload;
        return state;
    },
    deleteuser:state=>{
        state.username =''
        state.token =''
        state.isLogin =false
    }
  }
})

export const { setUser, deleteuser} = userSlice.actions

export default userSlice.reducer